package com.study.sxc.service;

import com.study.sxc.Dao.IMachineTypeDao;
import com.study.sxc.Entity.MachineType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class machineTypeService {

    private static final Logger log = LoggerFactory.getLogger(machineTypeService.class);

    @Resource
    IMachineTypeDao machineTypeDao;

    public List<MachineType> getMachineTypes(List<Integer> ids) {
        log.info("查询机型列表，参数：{}", ids);
        List<MachineType> types = machineTypeDao.getMachineTypes(ids);
        log.info("DAO层返回数据：{}", types);
        if(types == null || types.isEmpty()) {
            return new ArrayList<>();
        }
        return types;
    }

    public int addMachineType(MachineType machineType) {
        log.info("新增机型，参数：{}", machineType);
        int result = machineTypeDao.addMachineType(machineType);
        log.info("新增机型结果：{}", result);
        return result;
    }

    public int updateMachineType(MachineType machineType) {
        log.info("更新机型，参数：{}", machineType);
        int result = machineTypeDao.updateMachineType(machineType);
        log.info("更新机型结果：{}", result);
        return result;
    }

    public int deleteMachineType(Integer id) {
        log.info("删除机型，参数：{}", id);
        int result = machineTypeDao.deleteMachineType(id);
        log.info("删除机型结果：{}", result);
        return result;
    }

    public MachineType getMachineTypeById(Integer id) {
        return machineTypeDao.getMachineTypeById(id);
    }

    /**
     * 查询所有机型
     */
    public List<MachineType> getAllMachineTypes() {
        return machineTypeDao.getAllMachineTypes();
    }
} 